<template>
  <div style="align-items: center;">
    <div>
        <input placeholder="用户名" class="input" ref="username" @input="onNamechange" :autofocus=false value="" type="tel"/>
    </div>
    <div>
        <input placeholder="密码" class="input" ref="password" @input="onPwdchange" :autofocus=false value="" type="password"/>
    </div>
    <wxc-button text="登录"
              @wxcButtonClicked="wxcButtonClicked"></wxc-button>
  </div>
</template>
<script>
  import { WxcButton } from 'weex-ui';
  var modal = weex.requireModule("modal");

  export default {
    components: { WxcButton },
    data: function(){
      return {
        username:"",
        password:"",
      }
    },
    methods: {
      wxcButtonClicked () {
        console.log(this.username);
        if (this.username=="" || this.password == ""){
          modal.toast({
            message: "请输入信息",
            duration: 1
          });
          return
        }

        this.$notice.loading.show("loading");
        this.$fetch({
          method: 'GET',    // 大写
          url:'https://888.ph100.cn/login_password', //当前是在apis中配置的别名，你也可以直接绝对路径请求 如：url:http://xx.xx.com/xxx/xxx
          data: {
            phone: this.username,
            pwd: this.password
          }
        }).then(resData => {
          // 成功回调
          console.log(resData);
          this.$notice.loading.hide();
          modal.toast({
            message:resData["backstr"],
            duration: 1
          });

          this.$event.emit('getParams', "success?")
          this.$router.back({
              length: 1,
              type: 'PUSH'
          });
        }, error => {
          // 错误回调
          console.log(error);
          this.$notice.loading.hide();

          this.$event.emit('getParams', "success?")
          this.$router.back({
              length: 1,
              type: 'PUSH'
          });
        });
      },
      onNamechange(e) {
        this.username = e.value
      },
      onPwdchange(e) {
        this.password = e.value
      },
    },
  }
</script>

<style>
  .input{
    margin: 16px;
    padding: 8px;
    align-items: center;
    align-content: center;
    border-width: 2px;
    border-color: black;
  }
</style>
